05. Working with tables

What is a table?

A table is a collection of related data held in a table format within a database. It consists of columns, and rows.
In relational databases, a table is a set of data elements (values) using a model of vertical columns (identifiable by name) and horizontal rows, the cell being the unit where a row and column intersect. A table has a specified number of columns, but can have any number of rows. Each row is identified by one or more values appearing in a particular column subset. A specific choice of columns which uniquely identify rows is called the primary key.

JavaND#305 C04 L01 A05 Create Tables

The AUTO_INCREMENT attribute can be used to generate a unique identity for new rows.

CREATE TABLE animals (
     id MEDIUMINT NOT NULL AUTO_INCREMENT,
     name CHAR(30) NOT NULL,
     PRIMARY KEY (id)
);

INSERT INTO animals (name) VALUES
    ('dog'),('cat'),('penguin'),
    ('lax'),('whale'),('ostrich');

SELECT * FROM animals;
Results
id name
1 dog
2 cat
3 penguin
4 lax
5 whale
6 ostrich

Create Table

Task Description:

Create a table called post for posts in a blog. A blog has title, text and created time. The title can be up to 255 characters and the text can be up to 1000 characters. It should also have an auto-generated primary key.

Task List:

Task Feedback:

Wonderful! You now know how to create a table.

JavaND#305 C04 L01 A06 Alter Table

Alter Table Quiz

Task Description:

Modify the blog post table to increase the number of characters for blog text to 10,000. Add columns to capture the count of likes.

Task List:

Task Feedback:

Delightful! You have successfully modified a table.